package exemplo.faces;

import java.sql.SQLException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;


import exemplo.database.LoginDAO;
import exemplo.model.Login;

public class LoginConverter implements Converter{

	private LoginDAO loginDAO;
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		try {
			loginDAO = new LoginDAO();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		int code = Integer.parseInt(arg2);
		
		try {
			return loginDAO.getById(code);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		Login log = (Login) arg2;
		return log.toString();
	}

	
}
